package com.aos.iot.socket.common.parser;

import com.aos.iot.socket.common.message.Message;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class ParserFactor {

    private final Map<String, Parser<? extends Message>> protocolParserMap;

    public ParserFactor(List<Parser<? extends Message>> parsers) {
        this.protocolParserMap = parsers.stream().collect(Collectors.toMap(Parser::protocol, Parser::parser));
    }

    public <M extends Message> Parser<M> getParser(String protocol) {
        return (Parser<M>) protocolParserMap.get(protocol);
    }
}
